#coding=utf-8

import zlib 
import commonHelper

jsonFileConf = "conf.json" #配置清单 
jsonData = commonHelper.loadJson(jsonFileConf)

compressConf = jsonData["compressConf"]  #要压缩的js文件
jsCompressedOutput = jsonData["outputCompressedJs"]  #生成的路径的js压缩文件

commonHelper.initFileDir(jsCompressedOutput)

def compress(infile, dst, level=9):
    infile = open(infile, 'rb')
    dst = open(dst, 'wb')
    compress = zlib.compressobj(level)
    data = infile.read(1024)
    while data:
        dst.write(compress.compress(data))
        data = infile.read(1024)
    dst.write(compress.flush())


def decompress(infile, dst):
    infile = open(infile, 'rb')
    dst = open(dst, 'wb')
    decompress = zlib.decompressobj()
    data = infile.read(1024)
    while data:
        dst.write(decompress.decompress(data))
        data = infile.read(1024)
    dst.write(decompress.flush())

compress(compressConf,jsCompressedOutput)